package com.cloudauth.authgateway;


import com.cloudauth.authgateway.filter.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Random;

@RestController
@RequestMapping("/auth/")
public class TokenController {


    /**
     *  例子为了方便省掉具体的业务操作
     * @param userName
     * @param password
     * @param secret
     * @return
     */
    @GetMapping("/token")
    public String token(@RequestParam String userName,
                        @RequestParam String password,
                        @RequestParam String secret){

        //具体业务逻辑 数据库查询等 本例省略
        HashMap<String, Object> params = new HashMap<>();
        params.put("id",new Random().nextInt());
        params.put("user",userName);
        return JwtUtil.generateToken(params, secret);

    }





}
